@include('admin.public.head')

<div class="ibox-title">
    <h5>輪播圖添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="image" class="form-control"  value="">
                <img src="{{$result->banner_img??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">排序：</label>
            <div class="col-sm-9">
                <input type="text" name="order" class="form-control"  value="{{$result->order??'0'}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/banner" class="btn btn-primary" >返回輪播圖列表</a>
            </div>
        </div>
    </form>
</div>

<script>


    $('.do').click(function(){
        var form = new FormData();

        var id = $('input[name="id"]').val();
        var order = $('input[name="order"]').val();
        var image = $('input[name="image"]')[0].files[0];

        form.append("banner_img", image);
        form.append("id", id);
        form.append("order", order);

        $.ajax({
            type: 'POST',
            url: '/banner_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
